import {Directive} from '@angular/core';
import {FileUpload} from 'primeng/fileupload';
import {ErrorService} from '../api/ErrorService';

@Directive({
  selector: '[gnFileUpload]'
})
export class FileUploadDirective {

  constructor(private errorService: ErrorService,
              private button: FileUpload) {
    this.button.auto = true;
    this.button.mode = 'basic';

    this.button.onError.subscribe(event => {
      this.onError(event);
    });
  }

  onError(event) {
    this.errorService.occur({message: '上传文件错误', error: event});
  }

}
